package com.atguigu.binarysearch;

/**
 * @author xgc
 * @create 2021-07-22 10:40
 * 懒汉式（延迟加载）
 */
public class Singleton2 {
    //私有构造
    private Singleton2(){
        System.out.println("构造函数 Singleton2");
    }

    //初始值为Null
    private static Singleton2 singleton2 = null;

    //静态工厂方法
    public static Singleton2 getInstance(){
        if (singleton2 == null){
            System.out.println("getInstance");
            singleton2 = new Singleton2();
        }
        return singleton2;
    }

    public static void main(String[] args) {
        System.out.println("初始化");
        Singleton2 instance = singleton2.getInstance();
    }
}


